package bblvolume

import (
	"github.com/luosangnanka/goinfo"
	"runtime"
)

type VolStat struct {
	StoreStat *StorageStat
	Loadavg   *goinfo.Loadavg
	MemStat   *MemStat
	CPU       *goinfo.CPUInfo
}

type MemStat struct {
	Total     uint64
	Used      uint64
	Free      uint64
	Cached    uint64
	Buffers   uint64
	Self      uint64
	SwapTotal uint64
	SwapUsed  uint64
	SwapFree  uint64
}

func VolumeStat() (stat *VolStat) {
	stat = new(VolStat)
	memStat := new(runtime.MemStats)
	runtime.ReadMemStats(memStat)
	mem := MemStat{}
	mem.Self = memStat.Alloc
	free, _ := goinfo.Memory()
	mem.Total = uint64(free.Mem.Total)
	mem.Used = uint64(free.Mem.Used)
	mem.Free = uint64(free.Mem.Free)
	mem.Cached = uint64(free.Mem.Cached)
	mem.Buffers = uint64(free.Mem.Buffers)
	mem.SwapTotal = uint64(free.Swap.Total)
	mem.SwapUsed = uint64(free.Swap.Used)
	mem.SwapFree = uint64(free.Swap.Free)
	stat.MemStat = &mem
	cpu, _ := goinfo.CPU()
	stat.CPU = cpu[0]
	load, _ := goinfo.Load()
	stat.Loadavg = load
	return stat
}
